define(function(require, exports, module) {

  // var Backbone = require('backbone');
  var $ = require('jquery');
  var _ = require('underscore');
  // var jsonview = require('jsonview');
  var tmpl = require('text!../tmpl.html');

  // function instantiate(bytes, imports) {
  //   return WebAssembly.compile(bytes).then(function(m) {
  //     var instance = new WebAssembly.Instance(m, imports);
  //     return instance;
  //   });
  // }

  function main() {
    var $app = $('<div id="app">');
    $('#main').html($app);

    $app.append(tmpl);

    var importObject = {};

    fetch('/wasm/fibonacci/fib.wasm')
      .then(function(response) {
        var buf = response.arrayBuffer();
        return buf;
      })
      .then(function(bytes) {
        var results = WebAssembly.instantiate(bytes, importObject)
        return results;
      })
      .then(function(results) {
        var root = results.instance.exports;
        var fib = root.fib;
        console.log(fib(22))
      });
  }
  

  return main;
})
